﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Main.master" AutoEventWireup="true" CodeFile="orderdoc.aspx.cs" Inherits="Default2" %>

<%@ Register Assembly="DevExpress.Web.v12.2, Version=12.2.6.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxFormLayout" TagPrefix="dx" %>

<%@ Register Assembly="DevExpress.XtraReports.v12.2.Web, Version=12.2.6.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.XtraReports.Web" TagPrefix="dx" %>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="Server">
    <script src="../Scripts/toolbar.js" type="text/javascript"></script>
    <script language="javascript" type="text/javascript">
        // <![CDATA[
        function onChangeRow(values) {
            //OrderDoc_pnl.PerformCallback(values);
            //pnl_menuSpec.PerformCallback(values);
            var item = mMenu.GetItem(3);
            //alert(values);
            switch (values) {
                case 0:
                    item.SetImageUrl('/Images/shared/apply.png');
                    //mMenu.GetItem(3).GetMainElement().title = 'Провести документ';
                    break;
                case 1:
                    item.SetImageUrl('/Images/shared/unapply.png');
                    //mMenu.GetItem(3).GetMainElement().title = 'Отменить проведение документа';
                    break;
                default:
            }
        }

        function onComplete(values) {
            switch (values) {
                case 0:
                    cbk.PerformCallback('1');
                    //onChangeRow(1);
                    grd_OrderDoc.Refresh();
                    mMenu.GetItem(3).SetImageUrl('/Images/shared/unapply.png');
                    //pnl_menuSpec.PerformCallback(1);
                    break;
                case 1:
                    if (confirm('Вы действительно хотите отменить проведение документа?')) {
                        cbk.PerformCallback('0');
                        
                        //onChangeRow(0);
                        grd_OrderDoc.Refresh();
                        mMenu.GetItem(3).SetImageUrl('/Images/shared/apply.png');
                        //pnl_menuSpec.PerformCallback(0);
                    }
                    break;
            }


        }

        function onMenuClick(s, e) {
            switch (e.item.index) {
                case 3:
                    grd_OrderDoc.GetRowValues(grd_OrderDoc.GetFocusedRowIndex(), 'STATE', onComplete);
                    break;
                case 4:
                    e.item.NavigateUrl = '~/rep/orderRep.aspx?code=' + grd_OrderDoc.GetEditValue('CODE');
                    break;
                default: MenuItemClick(e, grd_OrderDoc);
            }
        }
        // ]]>
    </script>
    <div class="pageLabel">
        <dx:ASPxLabel ID="lbl_page" runat="server" Text="Движение документов" Font-Size="Medium" Theme="iOS">
        </dx:ASPxLabel>
    </div>
    <div style="float: left; margin-left: 10px;">
        <table style="margin-left: 10px">
            <tr>
                <td>
                    <dx:ASPxDateEdit ID="dt1" runat="server" Width="80px" AllowNull="False"></dx:ASPxDateEdit>
                </td>
                <td>
                    <dx:ASPxDateEdit ID="dt2" runat="server" Width="80px" AllowNull="False"></dx:ASPxDateEdit>
                </td>
                <td>
                    <dx:ASPxButton ID="btn_find" runat="server" Text="Запрос" OnClick="btn_find_Click" Theme="DevEx"></dx:ASPxButton>
                </td>
            </tr>
        </table>
        <dx:ASPxFormLayout ID="flt" runat="server" Theme="Metropolis" Width="100%">
            <Items>
                <dx:LayoutGroup Caption="Документ внутреннего перемещения ">
                    <Items>
                        <dx:LayoutItem Caption="Layout Item" ShowCaption="False">
                            <LayoutItemNestedControlCollection>
                                <dx:LayoutItemNestedControlContainer runat="server" SupportsDisabledAttribute="True">
                                    <dx:ASPxCallbackPanel ID="clb1" runat="server" ClientInstanceName="OrderDoc_pnl" EnableViewState="False" OnCallback="clb1_Callback" ShowLoadingPanel="False">
                                        <PanelCollection>
                                            <dx:PanelContent runat="server" SupportsDisabledAttribute="True">
                                                <dx:ASPxMenu ID="mMenu" ClientInstanceName="mMenu" runat="server" BackColor="Transparent" EnableViewState="False" EncodeHtml="False" ItemSpacing="1px" SeparatorHeight="15px" SeparatorWidth="2px">
                                                    <ClientSideEvents ItemClick="function(s, e) { onMenuClick(s, e); }" />
                                                    <SeparatorBackgroundImage ImageUrl="~\Images\shared\ToolBars\Office2003\SeparatorBackground.png" />
                                                    <Items>
                                                        <dx:MenuItem BeginGroup="True" GroupName="grp_edit" Name="btn_Insert" Text="" ToolTip="Добавить запись">
                                                            <Image Url="~/Images/shared/edit_add.png">
                                                            </Image>
                                                        </dx:MenuItem>
                                                        <dx:MenuItem GroupName="grp_edit" Name="btn_edit" Text="" ToolTip="Редактировать запись">
                                                            <Image Url="~/Images/shared/edit.png" UrlDisabled="~/Images/shared/edit_disable.png">
                                                            </Image>
                                                        </dx:MenuItem>
                                                        <dx:MenuItem GroupName="grp_edit" Name="btn_Delete" Text="" ToolTip="Удалит запись">
                                                            <Image Url="~/Images/shared/editdelete.png" UrlDisabled="~/Images/shared/editdelete_disable.png">
                                                            </Image>
                                                        </dx:MenuItem>
                                                        <dx:MenuItem GroupName="grp_settings" Name="btn_column" Text="">
                                                            <Image Url="~/Images/shared/apply.png">
                                                            </Image>
                                                        </dx:MenuItem>
                                                        <dx:MenuItem Name="btn_print" Target="_blank" Text="" ToolTip="Печать документа">
                                                            <Image Url="~/Images/shared/EXCEL.png">
                                                            </Image>
                                                        </dx:MenuItem>
                                                    </Items>
                                                </dx:ASPxMenu>
                                            </dx:PanelContent>
                                        </PanelCollection>
                                    </dx:ASPxCallbackPanel>
                                    <dx:ASPxGridView ID="grd_OrderDoc" ClientInstanceName="grd_OrderDoc" runat="server" AutoGenerateColumns="False" KeyFieldName="CODE"
                                        OnRowInserting="grd_OrderDoc_RowInserting"
                                        OnRowDeleting="grd_OrderDoc_RowDeleting"
                                        OnStartRowEditing="grd_OrderDoc_StartRowEditing" DataSourceID="ds_OrderDoc">
                                        <ClientSideEvents FocusedRowChanged="function(s, e) {
    grd_OrderDoc.GetRowValues(grd_OrderDoc.GetFocusedRowIndex(), 'STATE', onChangeRow);
	grd_OrderDoc.GetRowValues(grd_OrderDoc.GetFocusedRowIndex(), 'CODE', OnGetCodeValues);
}" />
                                        <Columns>
                                            <dx:GridViewDataTextColumn Caption="Код" FieldName="CODE" ReadOnly="True" ShowInCustomizationForm="True" VisibleIndex="1" Width="40px">
                                                <EditFormSettings Visible="False" />
                                                <DataItemTemplate>
                                                    <a href="orderspec.aspx?id=<%# Eval("CODE") %>" style="color: #000000"><%# Eval("CODE") %></a>
                                                </DataItemTemplate>
                                            </dx:GridViewDataTextColumn>
                                            <dx:GridViewDataComboBoxColumn Caption="Статус" FieldName="STATE" ShowInCustomizationForm="True" VisibleIndex="2" Width="80px">
                                                <PropertiesComboBox ValueType="System.Byte">
                                                    <Items>

                                                        <dx:ListEditItem Text="не проведен" Value="0" />

                                                        <dx:ListEditItem Text="проведен" Value="1" />

                                                    </Items>

                                                </PropertiesComboBox>
                                                <EditFormSettings Visible="False" />
                                            </dx:GridViewDataComboBoxColumn>
                                            <dx:GridViewDataDateColumn Caption="Дата документа" FieldName="DOCUMDATE" ShowInCustomizationForm="True" VisibleIndex="3" Width="80px">
                                            </dx:GridViewDataDateColumn>
                                            <dx:GridViewDataComboBoxColumn Caption="Создал" FieldName="OPERATOR" ShowInCustomizationForm="True" VisibleIndex="4" Width="120px">
                                                <PropertiesComboBox DataSourceID="ds_WORKER" TextField="FIO" ValueField="CODE" ValueType="System.Int32">
                                                </PropertiesComboBox>
                                                <EditFormSettings Visible="False" />
                                            </dx:GridViewDataComboBoxColumn>
                                            <dx:GridViewDataComboBoxColumn Caption="Тип операции" FieldName="OPERTYPE" ShowInCustomizationForm="True" VisibleIndex="5" Width="200px">
                                                <PropertiesComboBox ValueType="System.Int32">
                                                    <Items>

                                                        <dx:ListEditItem Text="передача документа в архив" Value="0" />

                                                        <dx:ListEditItem Text="выдача документа из архива" Value="1" />

                                                        <dx:ListEditItem Text="изъятие документа из архива" Value="2" />

                                                    </Items>

                                                </PropertiesComboBox>
                                            </dx:GridViewDataComboBoxColumn>
                                            <dx:GridViewDataComboBoxColumn Caption="Получил документ" FieldName="WORKER" ShowInCustomizationForm="True" VisibleIndex="6" Width="120px">
                                                <PropertiesComboBox DataSourceID="ds_WORKER" TextField="FIO" ValueField="CODE" ValueType="System.Int32">
                                                </PropertiesComboBox>
                                            </dx:GridViewDataComboBoxColumn>
                                            <dx:GridViewDataTextColumn Caption="Примечание" FieldName="NOTE" ShowInCustomizationForm="True" VisibleIndex="8">
                                            </dx:GridViewDataTextColumn>
                                            <dx:GridViewDataComboBoxColumn Caption="Объект" FieldName="ARCOBJECT" ShowInCustomizationForm="True" VisibleIndex="7" Width="120px">
                                                <PropertiesComboBox DataSourceID="ds_ArcObject" IncrementalFilteringMode="StartsWith" TextField="NAME" ValueField="CODE" ValueType="System.Int32">
                                                </PropertiesComboBox>
                                            </dx:GridViewDataComboBoxColumn>
                                            <dx:GridViewCommandColumn ShowInCustomizationForm="True" VisibleIndex="0">
                                                <ClearFilterButton Visible="True">
                                                </ClearFilterButton>
                                            </dx:GridViewCommandColumn>
                                        </Columns>
                                        <SettingsBehavior AllowFocusedRow="True" ConfirmDelete="True" EnableCustomizationWindow="true" AllowSelectByRowClick="True" AllowSelectSingleRowOnly="True" />
                                        <SettingsPager AlwaysShowPager="True">
                                            <PageSizeItemSettings Visible="True">
                                            </PageSizeItemSettings>
                                        </SettingsPager>

                                        <Settings ShowFilterRow="True" ShowFooter="True" />
                                    </dx:ASPxGridView>
                                    <asp:EntityDataSource ID="ds_WORKER" runat="server" ConnectionString="name=RegistRar" DefaultContainerName="RegistRar" EnableFlattening="False" EntitySetName="WORKER" Select="it.[CODE], it.[FIO]">
                                    </asp:EntityDataSource>
                                </dx:LayoutItemNestedControlContainer>
                            </LayoutItemNestedControlCollection>
                        </dx:LayoutItem>
                    </Items>
                </dx:LayoutGroup>
            </Items>
        </dx:ASPxFormLayout>
        <asp:EntityDataSource ID="ds_OrderDoc" runat="server" ConnectionString="name=RegistRar" DefaultContainerName="RegistRar" EnableDelete="True" EnableFlattening="False" EnableInsert="True" EnableUpdate="True" EntitySetName="ORDERDOC" Where="it.DOCUMDATE between @d1 and @d2">
            <WhereParameters>
                <asp:ControlParameter ControlID="dt1" DbType="DateTime" Name="d1" PropertyName="Value" />
                <asp:ControlParameter ControlID="dt2" DbType="DateTime" Name="d2" PropertyName="Value" />
            </WhereParameters>
        </asp:EntityDataSource>
        <dx:ASPxCallback ID="cbk" ClientInstanceName="cbk" runat="server" OnCallback="clb_Callback">
        </dx:ASPxCallback>
        <asp:EntityDataSource ID="ds_OrderSpec" runat="server" ConnectionString="name=RegistRar" DefaultContainerName="RegistRar" EnableDelete="True" EnableFlattening="False" EnableInsert="True" EnableUpdate="True" EntitySetName="ORDERSPEC" AutoGenerateWhereClause="True" Where="">
            <WhereParameters>
                <asp:SessionParameter DbType="Int32" DefaultValue="0" Name="ORDERDOC" SessionField="docCod" />
            </WhereParameters>
        </asp:EntityDataSource>
        <dx:ASPxLoadingPanel ID="loadpanel" ClientInstanceName="loadpanel" runat="server" ContainerElementID="flt$OrderSpec_pnl" Modal="True" Theme="iOS">
        </dx:ASPxLoadingPanel>
        <asp:EntityDataSource ID="ds_ArcPlace" runat="server" ConnectionString="name=RegistRar" DefaultContainerName="RegistRar" EnableFlattening="False" EntitySetName="ARCPLACE"
            Select="it.[CODE], it.[STRCODE]"
            Where="" EntityTypeFilter="">
        </asp:EntityDataSource>
        <asp:EntityDataSource ID="ds_ArcObject" runat="server" ConnectionString="name=RegistRar" DefaultContainerName="RegistRar" EnableFlattening="False" EntitySetName="ARCOBJECT">
        </asp:EntityDataSource>
    </div>
</asp:Content>

